package com.edward.demo.controller;

import com.edward.demo.service.IDemoService;
import com.edward.edu.mvcframework.annotations.EdwardSecurity;
import com.edward.edu.mvcframework.annotations.LagouAutowired;
import com.edward.edu.mvcframework.annotations.LagouController;
import com.edward.edu.mvcframework.annotations.LagouRequestMapping;

import javax.servlet.annotation.ServletSecurity;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author edward
 * @ProjectName springmvc-mydemo
 * @Description TODO
 * @time 2022/3/13 1:58 上午
 */
@LagouController
@LagouRequestMapping("/demo")
@EdwardSecurity({"employ", "project", "department"})
public class DemoController {

    @LagouAutowired
    private IDemoService demoService;

    /**
     * role只有 project 或 department 用户，才有访问权限
     * URL: /demo/query?name=lisi&role=project
     * @param request
     * @param response
     * @param name
     * @return
     */
    @LagouRequestMapping("/query")
    @EdwardSecurity({"project", "department"})
    public String query(HttpServletRequest request, HttpServletResponse response, String name, String role) {
        return demoService.get(name);
    }

    /**
     * role只有 employ 用户，才有访问权限
     * URL: /demo/query1?name=lisi&role=employ
     * @param request
     * @param response
     * @param name
     * @return
     */
    @LagouRequestMapping("/query1")
    @EdwardSecurity({"employ"})
    public String query1(HttpServletRequest request, HttpServletResponse response, String name, String role) {
        return demoService.get(name);
    }
}
